<?php

header('Content-Type: text/html;charset=UTF-8');
$_SESSION['page'] = 'duhoc';
$nt = isset($_GET['nt']) ? intval($_GET['nt']) : 0;

$nationlist = '';
$nationrows = Db::getRows('*', 'nation');
foreach ($nationrows as $nationrow) {
    $selected = $nationrow['id'] == $nt ? 'selected="selected"' : '';
    $nationlist .= '<option '.$selected.' value="'.$nationrow['id'].'">'.$nationrow['name'].'</option>';
}

$perPage = Config::get('num_per_page');
$pageNum = isset($_GET['p']) ? intval($_GET['p']) : 1;
if ($pageNum < 1) {
    $pageNum = 1;
}
if($nt > 0)
{
    $totalRows = Db::getOneField('COUNT(*)', 'article', 'type = 9 and nation='.$nt);
}
else
{
    $totalRows = Db::getOneField('COUNT(*)', 'article', 'type = 9');
}

$duhocpaging = Tpl::page($totalRows, $perPage, 'duhocList?nt='.$nt.'&p=');
$where = $nt > 0 ? 'type = 9 and nation ='.$nt : 'type = 9 ';
$rows = Db::getRows('*', 'article',$where .' order by id desc limit ' . ($pageNum - 1) * $perPage . ',' . $perPage);
$duhocresult = '';
foreach ($rows as $value => $row) {
    $id = $row['id'];
    $avatar = $row['img'];
    $title = $row['title'];
    $level = '';
    if($row['level']== '1')
    {
        $level = 'Trung học';
    }
    else if ($row['level']== '2')
    {
        $level = 'cao đẳng';
    }
    else if ($row['level']== '3')
    {
        $level = 'Đại học';
    }
    else
    {
        $level = 'Sau đại học';
    }
    $nation =Db::getOneField('name', 'nation', 'id='.$row['nation']);
    $posteddate = $row['posteddate'];
    $duhocresult.= '<tr>
                  <td class="check">'.++$value.'</td>
                  <td><img width="69px" height="37px" alt="No image" src="../upload/'.$avatar.'"></td>
                  <td class="item_name"><a title="" href="http://www.hocquocte.com/entry?id='.$id.'">'.$title.'</a></td>
                  <td class="quickaction">'.$level.'</td>
                  <td class="price">'.$nation.'</td>
                  <td class="status">'.$posteddate.'</td>
                  <td class="tool">
                      <a onclick="return confirm(\'Bạn có chắc chắn muốn xóa?\')" href="duhocDel?id='.$id.'&nt='.$nt.'&p='.$pageNum.'" class="btPink">
                          <span>
                              <span>Xóa</span>
                          </span>
                      </a>
                      <a href="duhocEdit?id='.$id.'" class="btBlue">
                          <span>
                              <span>Sửa</span>
                          </span>
                      </a>
                  </td>
                </tr>';
}
$duhocresult = $duhocresult == '' ? '<tr><td colspan="7">chưa có dữ liệu</td></tr>' : $duhocresult;
?>

